<div id="main"></div>    
<script type="text/javascript">
  function createLinks() { 
    <?php $supportedViews = GadgetsViews::getSupportedViews(true); ?>
    <?php $currentView = GadgetsViews::getCurrentView(true); ?>

    var text = [ "You are currently on the ", 
        <?php echo $currentView->getName(true) ?>, " isOnlyVisibleGadget: ", <?php echo $currentView->isOnlyVisibleGadget(true) ?>,
      " view.  Other views: " ].join(""); 

    //Set up some DOM  
    var outputdom = document.getElementById("main");
    outputdom.appendChild(document.createTextNode(text));   
    var ol = document.createElement("ol"); 
    outputdom.appendChild(ol);  
    //Iterate over each view  
    for ( <?php echo $supportedViews->eachAs('view') ?> ){
     <?php $view = $supportedViews->getView(); ?> 
      // Make some DOM to present each link    
      var li = document.createElement("li");    
      var a = document.createElement("a");    
      ol.appendChild(li);    
      li.appendChild(a);    
      a.href = "javascript:void(0);";    
      //Put the name of the view in the link    
      a.appendChild(document.createTextNode("Link to " + <?php echo $view->getName(true) ?>));    
      //Handle when the user clicks a link to the other server    
      a.onclick = getNavigateClosure(<?php echo $view->getVariable()->getName() ?>);  
   }
};

  /** 
   * Returns a function that navigates to the supplied view 
   */
    function getNavigateClosure(<?php echo $view->getVariable()->getName() ?>) {  
      return function() { <?php echo GadgetsViews::requestNavigateTo($view) ?> };
    };
  //Execute createLinks when the page is done loading
  <?php echo GadgetsUtil::registerOnLoadHandler(new JSFunction('createLinks')) ?>
  
</script>
 